/*
 * Copyright(c) 2018 优居科技 All rights reserved.
 * distributed with this file and available online at
 * http://www.yjyz.com/
 */
package com.zb.api.business.controller;


import com.zb.api.business.dto.PosPlanDto;
import com.zb.api.business.service.IPosPlanService;
import com.zb.api.common.models.Page;
import com.zb.api.common.models.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
* 方案表
 *
 * @author cwp
 * @version v1.0
 * @CreationTime: - 2022-02-08 14:19:31
 * @Description:
 */
@Api("方案表")
@RestController
@Slf4j
@RequestMapping("/PosPlan")
public class PosPlanController {

    @Resource
    private IPosPlanService posPlanService;

    @GetMapping("/lists")
    @ApiOperation(value="获取分页方案表数据", nickname = "posPlanList")
    public Result<Page<PosPlanDto>> posPlanList(@RequestParam(defaultValue = "1") @ApiParam(name = "pageNo", value = "当前页") int pageNo,
                                                @RequestParam(defaultValue = "10") @ApiParam(name = "pageSize", value = "每页记录数") int pageSize,
                                                PosPlanDto posPlanDto){
        return new Result("查询成功", posPlanService.getPosPlanList(pageNo, pageSize, posPlanDto));
    }

    @GetMapping("/{id}")
    @ApiOperation(value="获取方案表", nickname = "getPosPlan")
    public Result<PosPlanDto> getPosPlan(@PathVariable("id") String id) {
        return new Result("查询成功", posPlanService.get(id));
    }

    @PutMapping
    @ApiOperation(value="更新方案表", nickname = "updatePosPlan")
    public Result<Integer> updatePosPlan(@RequestBody PosPlanDto posPlanDto) {
        return new Result("修改成功", posPlanService.update(posPlanDto));
    }

    @PostMapping
    @ApiOperation(value="插入方案表", nickname = "insertPosPlan")
    public Result<Integer> insertPosPlan( @RequestBody PosPlanDto posPlanDto) {
        return new Result("录入成功", posPlanService.insert(posPlanDto));
    }

    @PostMapping("/insertPlan")
    @ApiOperation(value="添加方案", nickname = "insertPosPlan")
    public Result<Integer> insertPlan(@RequestBody PosPlanDto posPlanDto) throws IllegalAccessException {
        return new Result("录入成功", posPlanService.insertPlan(posPlanDto));
    }

    @PostMapping("/cancelPlan")
    @ApiOperation(value="上架/下架方案", nickname = "insertPosPlan")
    public Result<Integer> cancelPlan(@RequestBody PosPlanDto posPlanDto) throws IllegalAccessException {
        return new Result("操作成功", posPlanService.cancelPlan(posPlanDto));
    }


    @PostMapping("/updatePlan")
    @ApiOperation(value="修改方案", nickname = "insertPosPlan")
    public Result<Integer> updatePlan(@RequestBody PosPlanDto posPlanDto) throws IllegalAccessException {
        return new Result("修改成功", posPlanService.updatePlan(posPlanDto));
    }

    @PostMapping("/getPlanList")
    @ApiOperation(value="查询方案列表", nickname = "getPlanList")
    public Result<Page<PosPlanDto>> getPlanList(@RequestBody PosPlanDto posPlanDto) throws IllegalAccessException {
        return new Result("查询成功", posPlanService.getPlanList(posPlanDto));
    }

    @PostMapping("/getPlanInfo")
    @ApiOperation(value="查询方案详情", nickname = "getPlanInfo")
    public Result<PosPlanDto> getPlanInfo(@RequestBody PosPlanDto posPlanDto) throws IllegalAccessException {
        return new Result("查询成功", posPlanService.getPlanInfo(posPlanDto));
    }


    @PostMapping("/getRecommendList")
    @ApiOperation(value="查询推荐方案列表", nickname = "getRecommendList")
    public Result<Page<PosPlanDto>> getRecommendList(@RequestBody PosPlanDto posPlanDto) throws IllegalAccessException {
        return new Result("查询成功", posPlanService.getRecommendList(posPlanDto));
    }

    @PostMapping("/getHotList")
    @ApiOperation(value="查询热门方案列表", nickname = "getRecommendList")
    public Result<List<PosPlanDto>> getHotList() throws IllegalAccessException {
        return new Result("查询成功", posPlanService.getHotList());
    }

}
